<script setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { Gridors } from '@/stores/gridor.js'
import { storeToRefs } from 'pinia'

const gridors = Gridors()

const { list } = storeToRefs(gridors)

const router = useRouter()

const jump = (row) => {
  gridors.todo(row.id)
  // 在这里处理点击事件，例如导航到详情页或弹出对话框等
  router.push('/ftodo')
}

onMounted(() => {
  gridors.loadData()
})

const handleBackClick = () => {
  // 跳转回上一页
  gridors.goback2()
}
</script>

<template>
  <div class="public">
    <header class="header">
      <button class="back-button" @click="handleBackClick">返回</button>
      <h1 class="header-title">上报清单</h1>
    </header>
    <el-main style="background-color: #f3f4f6; flex: 1" class="main">
      <el-table :data="gridors.getData" style="width: 100%" @row-click="jump">
        <el-table-column prop="image" width="100px">
          <img :src="'https://via.placeholder.com/100'" class="item-image" />
        </el-table-column>

        <el-table-column>
          <template #default="item">
            <div style="display: flex; flex-direction: column">
              <el-text class="text1" style="width: 100%; height: 20%">
                <el-tag
                  :style="{ backgroundColor: item.row.color }"
                  style="color: white; font-weight: bold"
                  >{{ item.row.aqiExpln }}</el-tag
                >
                {{ this.$formatDate(item.row.updatetime, 'YYYY-MM-DD hh:mm:ss') }}
              </el-text>
              <el-text class="text2" style="width: 100%; height: 40%" line-clamp="2">{{
                item.row.faddress
              }}</el-text>
              <el-text class="text3" style="width: 100%; height: 40%"
                >备注：{{ item.row.remark }}</el-text
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </div>
</template>

<style scoped lang="scss">
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background-color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.back-button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #007bff;
}

.header-title {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.divider {
  height: 1px;
  background-color: #e0e0e0;
  margin: 0 20px;
}
.aqi {
  background-color: #f1f5f9;
}

.public {
  width: 410px;
  height: 640px;
}

.main {
  flex: 1; /* 填充剩余高度 */
  background-color: #f4f4f5; /* 示例背景色 */
  padding: 20px;
}
</style>
